package com.blog.cmrpersonalblog.entity;

import com.baomidou.mybatisplus.annotation.*;
import lombok.Data;

import java.time.LocalDateTime;

/**
 * 用户收藏实体类
 */
@Data
@TableName("user_collect")
public class UserCollect {

    /**
     * 收藏ID
     */
    @TableId(value = "id", type = IdType.AUTO)
    private Long id;

    /**
     * 用户ID
     */
    @TableField("user_id")
    private Long userId;

    /**
     * 文章ID
     */
    @TableField("article_id")
    private Long articleId;

    /**
     * 状态 0-取消收藏 1-收藏
     */
    @TableField("status")
    private Integer status;

    /**
     * 创建时间
     */
    @TableField(value = "create_time", fill = FieldFill.INSERT)
    private LocalDateTime createTime;

    /**
     * 更新时间
     */
    @TableField(value = "update_time", fill = FieldFill.INSERT_UPDATE)
    private LocalDateTime updateTime;

    /**
     * 状态常量
     */
    public static final int STATUS_UNCOLLECT = 0;
    public static final int STATUS_COLLECT = 1;

    /**
     * 是否收藏状态
     */
    public boolean isCollected() {
        return status != null && status == STATUS_COLLECT;
    }

    /**
     * 是否取消收藏状态
     */
    public boolean isUncollected() {
        return status != null && status == STATUS_UNCOLLECT;
    }
}
